<template>
    <div>
        <el-container>
            <el-main>
                <el-row>
                    <el-col :offset="11" v-show="!sData.isNull">
                        <span>创建时间：{{this.sData.form.ctime | unix2Date}}</span>-<span>修改时间：{{this.sData.form.mtime | unix2Date}}</span>
                    </el-col>
                </el-row>
                <el-divider></el-divider>
                <el-row>
                    <el-col>
                        <div v-html="sData.form.content" style="height: 500px"></div>
                    </el-col>
                </el-row>
            </el-main>
        </el-container>
    </div>
</template>

<script>
    export default {
        data () {
            return {
                sData: {
                    loading: false,
                    isNull: false,
                    form: {
                        id:-1,
                        content: '<h2>暂无内容</h2>',
                        ctime:undefined,
                        mtime:undefined,
                    },
                    rules: {
                        content: [
                            { required: true, message: '请输入内容', trigger: 'blur' },
                            { min: 3, max:300, message: '长度于 3-300 个字符', trigger: 'blur' },
                        ]
                    },
                },
                formLabelWidth: '120px'
            }
        },
        // manually control the data synchronization
        // 如果需要手动控制数据同步，父组件需要显式地处理changed事件
        methods: {
            getRightObligationByResident(){
                const _this = this;
                _this.sData.loading=true;
                this.getRequest("/rightobligation/residentGetRightObligation")
                    .then(resp =>{
                        if (resp && resp.data && resp.data.code === '200') {
                            const data = resp.data;
                            if (data.result){
                                _this.sData.form=data.result;
                                _this.sData.isNull=false;
                            }else {
                                _this.sData.isNull=true;
                            }
                            _this.sData.loading=false;
                        }else {
                            _this.sData.loading=false;
                        }
                    })
            }
        },
        computed: {
        },
        mounted() {
            this.getRightObligationByResident();
        },
        filters:{
            unix2Date: function (unixDate) {
                if (unixDate){
                    let date = new Date(unixDate);
                    let y = date.getFullYear();
                    let MM = date.getMonth() + 1;
                    MM = MM < 10 ? ('0' + MM) : MM;
                    let d = date.getDate();
                    d = d < 10 ? ('0' + d) : d;
                    let h = date.getHours();
                    h = h < 10 ? ('0' + h) : h;
                    let m = date.getMinutes();
                    m = m < 10 ? ('0' + m) : m;
                    let s = date.getSeconds();
                    s = s < 10 ? ('0' + s) : s;
                    return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
                }
            },
        }
    }
</script>
<style scoped>

</style>
